open(FOO,"../perl/NTDBNEW_Train_LD_for_R.txt");
open (OUT, '> NTDBNEW_Train_LD_R.txt');
print OUT "y\tcensor\tAge\tGender\tBloodPressure\tRespRate\tPulse\tGCS1\tGCS2\tGCS3\tGCS4\tGCS5\tGCS6\tGCS7\tGCS8\tGCS9\tGCS10\tGCS11\tGCS12\tGCS13\tINJ1\tINJ2\tINJ3\n";
while(<FOO>) {
    my %hICD;
    chomp;
    @t = split " ";
    @t1  = split ":",$t[0];
    print OUT $t1[0],"\t";    
    print OUT $t1[1],"\t";
    for ($i = 1; $i < @t; $i++)
    {
	@t1  = split ":",$t[$i];
	if ($t1[0] == 1) {$age = $t1[1];}
	if ($t1[0] == 2) {$gender = $t1[1];}
	if ($t1[0] == 3) {$bloodpressure = $t1[1];}
	if ($t1[0] == 4) {$resprate = $t1[1];}
	if ($t1[0] == 5) {$pulse = $t1[1];}
	if ($t1[0] >= 6) {$hICD{$t1[0]} = 1;}
    }
    print OUT "$age\t$gender\t$bloodpressure\t$resprate\t$pulse";
    for($i = 6; $i <= 21; $i++ )
    {
	if(exists($hICD{$i}))
	{
	    print OUT "\t1";
	}
	else
	{
	    print OUT "\t0";
	}
    }
    print OUT "\n";
}
close(OUT);